﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Please Select Document</title>
    <link rel="stylesheet" type="text/css" href="/lib/css/layout-default-latest.css" />
    <link rel="stylesheet" type="text/css" href="/lib/css/themes/base/jquery.ui.all.css" />
    <link href="/lib/css/StyleSheet1.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="/plugins/slick.grid.css" type="text/css" />
    <link rel="stylesheet" href="/lib/css/jquery.jdMenu.css" type="text/css" />
    <!-- CUSTOMIZE/OVERRIDE THE DEFAULT CSS -->
    <style type="text/css">
        /* remove padding and scrolling from elements that contain an Accordion OR a content-div */
        .outer-center, /* has content-div */ .outer-west, /* has Accordion */ .ui-layout-east, /* has content-div ... */ .ui-layout-east .ui-layout-content
        {
            /* content-div has Accordion */
            padding: 0;
            overflow: hidden;
        }
        .outer-center P.ui-layout-content
        {
            line-height: 1.4em;
            margin: 0; /* remove top/bottom margins from <P> used as content-div */
        }
        h3, h4
        {
            /* Headers & Footer in Center & East panes */
            font-size: 1.1em;
            background: #EEF;
            border: 1px solid #BBB;
            border-width: 0 0 1px;
            padding: 7px 10px;
            margin: 0;
        }
        .ui-layout-east h4
        {
            /* Footer in East-pane */
            font-size: 0.9em;
            font-weight: normal;
            border-width: 1px 0 0;
        }
        #loadingScreen
        {
            background: url(../images/ajax-loader.gif) no-repeat 5px 8px;
            padding-left: 25px;
        }
        .loadingScreenWindow .ui-dialog-titlebar-close
        {
            display: none;
        }
        
    </style>
    <script src="/lib/js/jquery-latest.js" type="text/javascript"></script>
    <script src="/lib/js/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/lib/js/jquery.layout-latest.js"></script>
    <script type="text/javascript" src="/lib/js/jquery.layout.resizePaneAccordions-1.0.js"></script>
    <script src="/plugins/globalize.js" type="text/javascript"></script>
    <script type="text/javascript" src="/lib/js/themeswitchertool.js"></script>
    <script type="text/javascript" src="/lib/js/debug.js"></script>
    <script type="text/javascript" src="/lib/js/jquery.dimensions.js"></script>
    <script type="text/javascript" src="/lib/js/jquery.positionBy.js"></script>
    <script type="text/javascript" src="/lib/js/jquery.bgiframe.js"></script>
    <script type="text/javascript" src="/lib/js/jquery.jdMenu.js"></script>
    <script src="/lib/js/jquery.event.drag-2.0.min.js"></script>
    <script src="/plugins/slick.editors.js"></script>
    <script src="/plugins/slick.core.js"></script>
    <script src="/plugins/slick.checkboxselectcolumn.js"></script>
    <script src="/plugins/slick.autotooltips.js"></script>
    <script src="/plugins/slick.cellrangedecorator.js"></script>
    <script src="/plugins/slick.cellrangeselector.js"></script>
    <script src="/plugins/slick.cellcopymanager.js"></script>
    <script src="/plugins/slick.cellselectionmodel.js"></script>
    <script src="/plugins/slick.rowselectionmodel.js"></script>
    <script src="/plugins/slick.formatters.js"></script>
    <script src="/plugins/slick.grid.js"></script>
    <script src="/plugins/surge.core.js" type="text/javascript"></script>
    <script src="/plugins/surge.slickGrid.js" type="text/javascript"></script>
    <script src="/Scripts/Helper.js" type="text/javascript"></script>
    <script src="/Scripts/AjaxLoading.js" type="text/javascript"></script>
    <script src="/Scripts/CurrentTime.js" type="text/javascript"></script>
    <script type="text/javascript">
        var helper = new Helper();
        $(document).ready(function () {
            var rolename = $.cookie("userrole");
            //            if (rolename == null || rolename.toLowerCase() != 'sale' || rolename.toLowerCase() != 'saleco') {
            //                window.location = '/Page/login.aspx';
            //            }
            helper.GetAllDocumentByUser('', function (data) {
                if (data != null || data != 'undefined') {
                    var allDocument = data.AllDocument;
                    var statusFilter = '50';
                    var statusFilter2 = '11';
                    var statusFilter3 = '40';
                    var statusFilter4 = '10';
                    allDocument = jQuery.grep(allDocument, function (n, i) {
                        return (n.Status.indexOf(statusFilter) >= 0 || n.Status.indexOf(statusFilter2) >= 0 || n.Status.indexOf(statusFilter3) >= 0 || n.Status.indexOf(statusFilter4) >= 0);
                    });
                    var gridID = '#gridDocumentListToReport';
                    GridDocumentListInit(gridID, allDocument, 'all');
                }
            });
            $("#btnConfirmSelect")
                        .button({
                            icons: {
                                primary: "ui-icon-circle-close"
                            }
                        })
                        .click(function () {
                            var selectedDoc = [];
                            var selectDoc = documentgrid.getSelectedRows();
                            if (selectDoc.length > 0) {
                                jQuery.each(selectDoc, function (index, value) {
                                    selectedDoc.push(documentgrid.getData()[value]["DocID"]);
                                });
                                helper.GetCustomerListByDocs(selectedDoc, function (custs) {
                                    var htmlCustItme = "<a href='#' onclick='showReport(\"xxx\")'>{0}</a><br /><br />";
                                    var htmlComp = '';
                                    $.each(custs.All, function (key, value) {
                                        var itemcomp = htmlCustItme.format(value.RefDisplay);
                                        itemcomp = itemcomp.replace(/xxx/g, value.RefID);
                                        htmlComp += itemcomp;
                                    });
                                    $('#sapExportTextDownloadContent').html(htmlComp);
                                    $("#sapExportTextDownload").dialog('open');
                                    var top = ($(window).height() - 400) / 2;
                                    var left = ($(window).width() - 200) / 2;

                                    $(".Dialog").css('left', left);
                                    $(".Dialog").css('top', top);
                                });
                            }

                        });

            $("#sapExportTextDownload").dialog({
                autoOpen: false,
                resizable: true,
                height: 400,
                width: 250,
                dialogClass: "Dialog",
                title: "Customer's Report",
                modal: true,
                buttons: {
                    Ok: function () {
                        $(this).dialog("close");

                    }
                }
            });
        });
        function EnterShowCustomer(docid) {
            var selectedDoc = [];
           
            selectedDoc.push(docid);
               
                helper.GetCustomerListByDocs(selectedDoc, function (custs) {
                    var htmlCustItme = "<a href='#' onclick='showReport(\"xxx\")'>{0}</a><br /><br />";
                    var htmlComp = '';
                    $.each(custs.All, function (key, value) {
                        var itemcomp = htmlCustItme.format(value.RefDisplay + " (" + value.RefID + ")");
                        itemcomp = itemcomp.replace(/xxx/g, value.RefID);
                        htmlComp += itemcomp;
                    });
                    $('#sapExportTextDownloadContent').html(htmlComp);
                    $("#sapExportTextDownload").dialog('open');
                    var top = ($(window).height() - 400) / 2;
                    var left = ($(window).width() - 200) / 2;

                    $(".Dialog").css('left', left);
                    $(".Dialog").css('top', top);
                });
    
        }

        var documentgrid;
    function GridDocumentListInit(gridtarget, allDocument, searchText) {
        var columnGridDocument = [
                { id: "DocID", name: "ID", field: "DocID", width: 120, cssClass: "cell-title" },
                { id: "DocType", name: "Document Type", field: "Doctype", width: 120, cssClass: "cell-title", formatter: Slick.Formatters.DocType},
//                { id: "Status", name: "Status", field: "Status" },
                { id: "Create By", name: "Create By", field: "UserName", width: 80, resizable: false },
                { id: "Create On", name: "Create On", field: "Created", minWidth: 60, formatter: Slick.Formatters.ToDate },
                { id: "Approved On", name: "Approved On", field: "ApproveDate", minWidth: 60, formatter: Slick.Formatters.ToDate },
                { id: "Status", name: "Status", field: "Status", width: 110, cssClass: "cell-title", formatter: Slick.Formatters.Status },
                { id: "Enter", name: "", field: "DocID", formatter: Slick.Formatters.EnterShowCustomer }
                
            ];
        var optionsDocumentGrid = {
            editable: false,
            enableRowReordering: true,
            enableCellNavigation: true,
            asyncEditorLoading: false,
            autoEdit: false
        };

        if (searchText === 'all') {
            allDocument = allDocument;
        }
        else {
            allDocument = jQuery.grep(allDocument, function (n, i) {
                return (n.Status.indexOf(searchText) >= 0);
            });
        }
        //var checkboxSelector = new Slick.CheckboxSelectColumn({
        //    cssClass: "slick-cell-checkboxsel"
        //});
        //columnGridDocument.splice(0, 0, checkboxSelector.getColumnDefinition());
        var datas = allDocument;
        documentgrid = new Slick.Grid(gridtarget, datas, columnGridDocument, optionsDocumentGrid);
        documentgrid.setSelectionModel(new Slick.RowSelectionModel({ selectActiveRow: true }));
        //documentgrid.registerPlugin(checkboxSelector);
        documentgrid.onCellChange.subscribe(function (e, args) {
            //updateUser(args.item);
        });
        //documentgrid.registerPlugin(checkboxSelector);
    }

    function showReport(custID,docID) {

        var selectedDoc = [];
        var selectDoc = documentgrid.getSelectedRows();
        jQuery.each(selectDoc, function (index, value) {
            selectedDoc.push(documentgrid.getData()[value]["DocID"]);
        });
        var url = "/Page/ReportViewer.aspx?cusID=" + custID + "&docs=";
        var docs = '';
        
        jQuery.each(selectedDoc, function (index, value) {
            docs += value + ',';
        });
        docs = docs.slice(0, -1);
        if (docID != undefined) {
            docs = docID;
        }
        
        url += docs;
        window.open(encodeURI(url), "report");
    }
    </script>
</head>
<body>
    <div id="mainFrame" class="ui-layout-center" width="100%" height="600" frameborder="0"
        scrolling="auto">
        <div id="DocumentListAdminStep">
            <!--<div style="padding-top: 10px; padding-bottom: 30px; padding-left: 10px; padding-right: 10px;">
                <span style="float: left">Quick Search&nbsp;<input type="text" maxlength="50"></span>
            </div>-->
            <div id="gridDocumentListToReport" style="height: 550px; margin-top: 20px; margin-bottom: 20px;">
            </div>
            <button id="btnConfirmSelect" style="display:none;">
                OK
            </button>
        </div>
    </div>
    <div id="sapExportTextDownload" style="overflow-y: scroll;">
        <div id="sapExportTextDownloadContent" style="margin: 10px;" >
            
        </div>
    </div> 
</body>
</html>
